﻿@using Telerik.Web.Mvc.UI;

@model ProductBundleItemModel

@{
    Layout = "_AdminPopupLayout";
}

@using (Html.BeginForm(new { btnId = ViewBag.BtnId, formId = ViewBag.FormId }))
{
    @Html.ValidationSummary(false)
    @Html.HiddenFor(model => model.Id)
    @Html.HiddenFor(model => model.ProductId)
    @Html.HiddenFor(model => model.BundleProductId)
    
    <div class="section-header">
        <div class="title">@ViewBag.Title</div>
		<div class="options">
			<button type="submit" name="save" value="save" class="btn btn-warning">
				<i class="fa fa-check"></i>
				<span>@T("Admin.Common.Save")</span>
			</button>
			<button type="submit" name="save-continue" value="save-continue" class="btn btn-secondary">
				@T("Admin.Common.SaveContinue")
			</button>
		</div>
	</div>
	
	<script type="text/javascript">
		$(document).ready(function () {

			@foreach (var attribute in Model.Attributes)
			{
				<text>
				$('#attribute_@attribute.Id').selectWrapper();
				</text>
			}
		});
	</script>
    	
	@Html.SmartStore().TabStrip().Name("bundleitem-edit").Style(TabsStyle.Material).Items(x =>
	{
		x.Add().Text(T("Common.General").Text).Content(TabInfo()).Selected(true);
		x.Add().Text(T("Admin.Catalog.Products.BundleItems.Attributes").Text).Content(TabAttributeFilters());

		EngineContext.Current.Resolve<IEventPublisher>().Publish(new TabStripCreated(x, "bundleitem-edit", this.Html, this.Model));
	})

	@helper TabInfo()
	{
		<div id="BundleItemsLocalizedContainer">
			@(Html.LocalizedEditor<ProductBundleItemModel, ProductBundleItemLocalizedModel>("productbundleitem-localized",
			@<table class="adminContent">
				<tr>
					<td class="adminTitle">
						@Html.SmartLabelFor(model => model.Locales[item].Name)
					</td>
					<td class="adminData">
						@*IMPORTANT: Do not delete, this hidden element contains the id to assign localized values to the corresponding language *@
						@Html.HiddenFor(model => model.Locales[item].LanguageId)

						@Html.EditorFor(model => Model.Locales[item].Name)
						@Html.ValidationMessageFor(model => model.Locales[item].Name)
					</td>
				</tr>
				<tr>
					<td class="adminTitle">
						@Html.SmartLabelFor(model => model.Locales[item].ShortDescription)
					</td>
					<td class="adminData">
						@Html.EditorFor(model => model.Locales[item].ShortDescription)
						@Html.ValidationMessageFor(model => model.Locales[item].ShortDescription)
					</td>
				</tr>
			</table>
			,
			@<table class="adminContent">
				<tr>
					<td class="adminTitle">
						@Html.SmartLabelFor(model => model.Name)
					</td>
					<td class="adminData">
						@Html.EditorFor(model => model.Name)
						@Html.ValidationMessageFor(model => model.Name)
					</td>
				</tr>
				<tr>
					<td class="adminTitle">
						@Html.SmartLabelFor(model => model.ShortDescription)
					</td>
					<td class="adminData">
						@Html.EditorFor(x => x.ShortDescription)
						@Html.ValidationMessageFor(model => model.ShortDescription)
					</td>
				</tr>
			</table>
			))
		</div>

		<table class="adminContent">
			<tr>
				<td class="adminTitle">
					@Html.SmartLabelFor(model => model.Quantity)
				</td>
				<td class="adminData">
					@Html.EditorFor(model => model.Quantity)
					@Html.ValidationMessageFor(model => model.Quantity)
				</td>
			</tr>
			@if (Model.IsPerItemPricing)
			{
			<tr>
				<td class="adminTitle">
					@Html.SmartLabelFor(model => model.Discount)
				</td>
				<td class="adminData">
					@Html.EditorFor(model => model.Discount)
					@Html.ValidationMessageFor(model => model.Discount)
				</td>
			</tr>
			<tr>
				<td class="adminTitle">
					@Html.SmartLabelFor(model => model.DiscountPercentage)
				</td>
				<td class="adminData">
					@Html.EditorFor(model => model.DiscountPercentage)
					@Html.ValidationMessageFor(model => model.DiscountPercentage)
				</td>
			</tr>
			}
			<tr>
				<td class="adminTitle">
					@Html.SmartLabelFor(model => model.HideThumbnail)
				</td>
				<td class="adminData">
					@Html.EditorFor(model => model.HideThumbnail)
					@Html.ValidationMessageFor(model => model.HideThumbnail)
				</td>
			</tr>
			<tr>
				<td class="adminTitle">
					@Html.SmartLabelFor(model => model.Visible)
				</td>
				<td class="adminData">
					@Html.EditorFor(model => model.Visible)
					@Html.ValidationMessageFor(model => model.Visible)
				</td>
			</tr>
			<tr>
				<td class="adminTitle">
					@Html.SmartLabelFor(model => model.Published)
				</td>
				<td class="adminData">
					@Html.EditorFor(model => model.Published)
					@Html.ValidationMessageFor(model => model.Published)
				</td>
			</tr>
			<tr>
				<td class="adminTitle">
					@Html.SmartLabelFor(model => model.DisplayOrder)
				</td>
				<td class="adminData">
					@Html.EditorFor(model => model.DisplayOrder)
					@Html.ValidationMessageFor(model => model.DisplayOrder)
				</td>
			</tr>
			<tr>
				<td class="adminTitle">
					@Html.SmartLabelFor(model => model.CreatedOn)
				</td>
				<td class="adminData">
					<div class="form-control-plaintext">
						@Html.DisplayFor(model => model.CreatedOn)
					</div>
				</td>
			</tr>
			<tr>
				<td class="adminTitle">
					@Html.SmartLabelFor(model => model.UpdatedOn)
				</td>
				<td class="adminData">
					<div class="form-control-plaintext">
						@Html.DisplayFor(model => model.UpdatedOn)
					</div>
				</td>
			</tr>
		</table>
	}
	
	@helper TabAttributeFilters()
	{
		if (Model.Attributes.Count == 0)
		{
			<div class="alert alert-warning">
				@T("Admin.Catalog.Products.BundleItems.Fields.FilterAttributes.NoneNote")
			</div>
			return;
		}
		<table class="adminContent">
			<tr>
				<td class="adminTitle">
					@Html.SmartLabelFor(model => model.FilterAttributes)
				</td>
				<td class="adminData">
					@Html.CheckBoxFor(model => model.FilterAttributes, new { data_toggler_for = "#AttributeFilters" })
					@Html.ValidationMessageFor(model => model.FilterAttributes)
				</td>
			</tr>
			<tbody id="AttributeFilters">
				@foreach (var attribute in Model.Attributes)
				{
					<tr>
						<td class="adminTitle">
							@Html.SmartLabel(attribute.AttributeControlId, attribute.Name)
						</td>
						<td class="adminData">
							@Html.DropDownList(attribute.AttributeControlId, attribute.Values, null, new { multiple = "multiple", @class = "form-control" })
						</td>
					</tr>
					if (attribute.PreSelect.Count > 0)
					{
						<tr>
							<td class="adminTitle">
								@Html.SmartLabel(attribute.PreSelectControlId, T("Admin.Catalog.Products.BundleItems.Fields.FilterPreSelect"), T("Admin.Catalog.Products.BundleItems.Fields.FilterPreSelect.Hint"))
							</td>
							<td class="adminData">
								@Html.DropDownList(attribute.PreSelectControlId, attribute.PreSelect, new { @class = "form-control" })
							</td>
						</tr>
					}
				}
			</tbody>
		</table>
	}
}